<!DOCTYPE html>
<html style="height:auto; min-height: 100%;">
<head>
    <meta charset="utf-8"/>
    <title>QuickD 前后端分离快速开发平台</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="css/toastr.min.css" rel="stylesheet" type="text/css"/>
    <link href="css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link rel="icon" href="img/favicon.ico"/>
    <link rel="stylesheet" href="./css/start-pc.css" media="screen and (min-width: 640px)"/>
    <link rel="stylesheet" href="./css/start-mobile.css" media="screen and (max-width: 640px)"/>
</head>
<body>
<div id="main" style="overflow-x: hidden">
    <div class="header-box">
        <a href="/"><img src="img/logo.png" alt="QuickD logo" target="_blank"/></a>
        <h3>生成初始项目</h3>
    </div>
    <form class="form-horizontal">
        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <h4 class="group-title"><span class="font-red">*</span>项目配置：</h4>
                <hr/>
            </div>
        </div>
        <div class="form-group">
            <label for="groupName" class="control-label col-md-2">Group:</label>
            <div class="col-md-3">
                <input type="text" class="form-control" id="groupName" value="com.quickd" placeholder="com.quickd"/>
            </div>
            <label for="sysName" class="control-label col-md-2">项目中文名称:</label>
            <div class="col-md-3">
                <input type="text" class="form-control" id="sysName" value="企业级快速开发平台" placeholder="demo"/>
            </div>
        </div>
        <div class="form-group">
            <label for="author" class="control-label col-md-2">author:</label>
            <div class="col-md-3">
                <input type="text" class="form-control" id="author" value="quickd" placeholder="author"/>
            </div>
            <label for="copyright" class="control-label col-md-2">copyright:</label>
            <div class="col-md-3">
                <input type="text" class="form-control" id="copyright" value="www.iquickd.com"
                       placeholder="www.iquickd.com"/>
            </div>
        </div>

        <div class="form-group">
            <label for="project" class="control-label col-md-2">项目英文名称:</label>
            <div class="col-md-3">
                <input type="text" class="form-control" id="project" value="demo" placeholder="项目英文名称"/>
            </div>
            <label for="genPath" class="control-label col-md-2">生成代码路径:</label>
            <div class="col-md-3">
                <input type="text" class="form-control" id="genPath" value="/data/project" placeholder="请输入生成代码路径"/>
            </div>
        </div>
        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <h4 class="group-title">数据库连接信息：</h4>
                <hr/>
            </div>
        </div>
        <div class="form-group">
            <label for="dbUrl" class="control-label col-md-2">地址：</label>
            <div class="col-md-3">
                <input id="dbUrl" type="text" class="form-control" value="127.0.0.1" placeholder="127.0.0.1"/>
            </div>
            <label for="dbPort" class="control-label col-md-2">端口：</label>
            <div class="col-md-3">
                <input id="dbPort" type="text" class="form-control" value="3306" placeholder="3306"/>
            </div>
        </div>
        <div class="form-group">
            <label for="dbUsername" class="control-label col-md-2">用户名：</label>
            <div class="col-md-3">
                <input id="dbUsername" type="text" class="form-control" value="root" placeholder="数据库用户名"/>
            </div>
            <label for="dbPassword" class="control-label col-md-2">数据库密码：</label>
            <div class="col-md-3">
                <input id="dbPassword" type="text" class="form-control" value="123456" placeholder="数据库密码"/>
            </div>
        </div>

        <div class="form-group">

            <label for="dbName" class="control-label col-md-2">数据库名：</label>
            <div class="col-md-3">
                <input id="dbName" type="text" class="form-control" value="demo" placeholder="数据库名"/>
            </div>
            <div class="col-md-3">
                <label><input type="checkbox" id="isInitDb" value="true"/>初始化数据库和表</label>
            </div>
        </div>

        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <h4 class="group-title"><span class="font-red">*</span>组件配置：</h4>
                <hr/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-6 col-md-offset-1 form-group-first">
                <div class="checkbox children-space-split">
                    <label for="redis"><input type="checkbox" id="redis" value="redis"/>redis</label>
                    <label for="mongo"><input type="checkbox" id="mongo" value="mongo"/>mongo</label>
                    <label for="activiti"><input type="checkbox" id="activiti"
                                                 value="activiti"/>activiti</label>
                    <label for="quartz"><input type="checkbox" id="quartz" value="quartz"/>quartz</label>
                    <label for="oss"><input type="checkbox" id="oss" value="oss"/>oss</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <p>
                <button type="button" class="btn btn-primary" id="btnGenera" onclick="submitForm()">生成项目</button>
            </p>
        </div>
    </form>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/toastr.min.js"></script>
<script type="text/javascript">
    function submitForm() {
        var components="";
        if( $('#redis').val()){
            components+=$('#redis').val()+",";
            components+=$('#mongo').val()+",";
            components+=$('#activiti').val()+",";
            components+=$('#quartz').val()+",";
            components+=$('#oss').val()+",";
        }
        var dataForm = {
            project: $('#project').val(),
            groupName: $('#groupName').val(),
            copyright: $('#copyright').val(),
            author: $('#author').val(),
            dbUrl: $('#dbUrl').val(),
            dbPort: $('#dbPort').val(),
            dbName: $('#dbName').val(),
            dbUsername: $('#dbUsername').val(),
            dbPassword: $('#dbPassword').val(),
            components: components,
            isInitDb: $('#isInitDb').val(),
            sysName: $('#sysName').val(),
            genPath: $('#genPath').val(),
        };
        $.ajax({
            type: "POST",
            url: "./gen/project/gen-code",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(dataForm),
            xhrFields: {
                responseType: 'blob'
            },
            error: function (request) {
                alert("提交出错 error");
            },
            success: function (data) {
                var url = window.URL.createObjectURL(new Blob([data]));
                var link = document.createElement('a');
                link.style.display = 'none';
                link.href = url;
                link.setAttribute('download',  "quickd.zip");
                document.body.appendChild(link);
                link.click();
            }
        });
    }

</script>
</body>
</html>